package com.dinggao.crossgo.core.observer;

/**
 * created by mapingan on 2018/8/10.
 */
public class EventIntet {

    private static EventIntet instance;
    private ConcreteObservableA observableA;

    public static EventIntet getDefault() {
        if (instance == null) {
            synchronized (EventIntet.class) {
                if (instance == null) {
                    instance = new EventIntet();
                }
            }
        }
        return instance;
    }

    private EventIntet() {
        observableA = new ConcreteObservableA();
    }

    /**
     * register a privateObserver
     * @param privateObserver
     */
    public void register(PrivateObserver privateObserver) {
        observableA.addObserver(privateObserver);
    }

    /**
     * unregister a privateObserver
     * @param privateObserver
     */
    public void unregister(PrivateObserver privateObserver) {
        observableA.removeObserver(privateObserver);
    }

    /**
     * post a objict message to all observer
     * @param obj
     */
    public void post(Object obj) {
        observableA.notifyObservers(obj);
    }

}